package com.king.nio.filechannel;

import java.nio.ByteBuffer;

/**
 * ByteBuffer Put Get
 *
 * @author king
 * @date 2020/12/27 14:49
 */
public class NioByteBufferPutGet {
    public static void main(String[] args) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(64);

        byteBuffer.putInt(128);
        byteBuffer.putLong(999);
        byteBuffer.putChar('国');
        byteBuffer.putShort((short) 4);

        byteBuffer.flip();

        // 按照对应类型输出
        System.out.println(byteBuffer.getInt());
        System.out.println(byteBuffer.getLong());
        System.out.println(byteBuffer.getChar());
        System.out.println(byteBuffer.getShort());

        // 不按照对应类型输出
//        System.out.println(byteBuffer.getLong());
//        System.out.println(byteBuffer.getLong());
//        System.out.println(byteBuffer.getLong());
//        System.out.println(byteBuffer.getLong());
    }
}
